﻿using System;
using System.Windows.Controls;

namespace IntoNails.Infrastructure.InteractionRequests
{
    public enum InteractionDialogResult
    {
        Submit,
        Cancel,
    }

    public class InteractionDialogBase<T> : UserControl
    {
        protected class InteractionEventArgs : EventArgs
        {
            internal InteractionDialogResult DialogResult { get; private set; }

            internal InteractionEventArgs(InteractionDialogResult dialogResult)
            {
                this.DialogResult = dialogResult;
            }

            public override string ToString()
            {
                return this.DialogResult.ToString();
            }
        }

        public InteractionDialogBase()
        {
        }

        public event EventHandler DialogSubmit;
        public event EventHandler DialogCancel;

        public virtual void Submit()
        {
            this.OnClose(new InteractionEventArgs(InteractionDialogResult.Submit));
        }

        public virtual void Cancel()
        {
            this.OnClose(new InteractionEventArgs(InteractionDialogResult.Cancel));
        }

        protected virtual void OnClose(InteractionEventArgs e)
        {
            var handler = (e.DialogResult == InteractionDialogResult.Submit) ? this.DialogSubmit : this.DialogCancel;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }
}
